package com.njrsrc.android.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.njrsrc.R;

public class TitleBar extends RelativeLayout {
	public ImageButton back;
	public ImageButton right;
	public ImageButton rightOfLeft;
	public TextView title;

	public TitleBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.titlebar, this);
		back = (ImageButton) findViewById(R.id.tb_ibtn_back);
		right = (ImageButton) findViewById(R.id.tb_ibtn_right);
		rightOfLeft = (ImageButton) findViewById(R.id.tb_ibtn_right_of_left);
		title = (TextView) findViewById(R.id.tb_tv_title);
	}

	/**
	 * 设置左侧按钮(ImageButton)图片资源
	 */
	public void setLeftBg(int resId) {
		back.setImageResource(resId);
	}

	/**
	 * 设置显示的文字 title.setText(text);
	 */
	public void setTitleText(String text) {
		title.setText(text);
	}

	public void setRightBg(int resId) {
		right.setVisibility(View.VISIBLE);
		right.setImageResource(resId);
	}

	public void setRightOfLeftBg(int resId) {
		rightOfLeft.setVisibility(View.VISIBLE);
		rightOfLeft.setImageResource(resId);
	}
	
	public void setTitleLayoutParams()
	{
		RelativeLayout.LayoutParams layoutParams = 
				new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		layoutParams.addRule(RelativeLayout.LEFT_OF, R.id.tb_ibtn_right_of_left);
		layoutParams.addRule(RelativeLayout.RIGHT_OF, R.id.tb_ibtn_back);
		layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
		title.setGravity(Gravity.CENTER);
		title.setLayoutParams(layoutParams);
	}
}